package powerdev.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Time;
import java.util.Date;

import powerdev.excepcion.DAOExcepcion;
import powerdev.modelo.Tarifa;
import powerdev.util.ConexionBD;



public class TarifaDAO extends BaseDAO {
	public void insertarTarifa(Tarifa vo,int co_Lista, int co_Cancha, Time nu_HoraI, Time nu_HoraF, double ss_PrecioxHora, String tx_Glosa, boolean fl_Estado) throws DAOExcepcion {
		System.out.println("CanchaDAO: insertar(Cancha vo)");
		String query = "INSERT INTO Tarifa(co_Lista, co_Cancha, nu_HoraI, nu_HoraF, ss_PrecioxHora, tx_Glosa, fl_Estado) VALUES (?,?,?,?,?,?,?)";
		Connection con = null;
		PreparedStatement stmt = null;
		try {
			con = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);
			stmt.setInt(1, vo.getCo_Lista());
			stmt.setInt(2, vo.getCo_Cancha());
			stmt.setTime(3, (java.sql.Time)  vo.getNu_HoraI());
			stmt.setTime(4, (java.sql.Time)  vo.getNu_HoraF());
			stmt.setDouble(5, vo.getSs_PrecioxHora());
			stmt.setString(6, vo.getTx_Glosa());
			stmt.setBoolean(7, vo.isFl_Estado());
			int i = stmt.executeUpdate();
			System.out.println(vo.getCo_Lista());
			if (i != 1) {
				throw new SQLException("No se pudo insertar");
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
	}

	public void insertarTarifa(Tarifa vo) throws DAOExcepcion {
		// TODO Auto-generated method stub
		System.out.println("CanchaDAO: insertar(Cancha vo)");
		String query = "INSERT INTO Tarifa(co_Lista, co_Cancha, nu_HoraI, nu_HoraF, ss_PrecioxHora, tx_Glosa, fl_Estado) VALUES (?,?,?,?,?,?,?)";
		Connection con = null;
		PreparedStatement stmt = null;
		try {
			con = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);
			stmt.setInt(1, vo.getCo_Lista());
			stmt.setInt(2, vo.getCo_Cancha());
			stmt.setTime(3, (java.sql.Time)  vo.getNu_HoraI());
			stmt.setTime(4, (java.sql.Time)  vo.getNu_HoraF());
			stmt.setDouble(5, vo.getSs_PrecioxHora());
			stmt.setString(6, vo.getTx_Glosa());
			stmt.setBoolean(7, vo.isFl_Estado());
			int i = stmt.executeUpdate();
			System.out.println(vo.getCo_Lista());
			if (i != 1) {
				throw new SQLException("No se pudo insertar");
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
	}
}
